package com.shangma.cn.commons.upload;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.InputStream;

/**
 * 开发人员: 辉哥真球帅
 * 联系方式: zhengzhoudaxuevip@163.com
 * 创建时间: 2021/9/30  15:28
 * 文件含义:
 */

public class UploadUtils {

    /**
     *  1: 导入包
     *          <dependency>
     *             <groupId>com.aliyun.oss</groupId>
     *             <artifactId>aliyun-sdk-oss</artifactId>
     *             <version>3.10.2</version>
     *         </dependency>
     *
     *
     *
     *
     */


    public static  String upload(String fileName, InputStream in) {
        String endpoint = "https://oss-cn-beijing.aliyuncs.com";
        String accessKeyId = "LTAI5tKvEqxy8zZ56N4xiSQG";
        String accessKeySecret = "DPzLmjm1dywaX8xU1Lar65JeOm7dpt";
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        ossClient.putObject("nimeide", fileName, in);
        ossClient.shutdown();
        String url = "http://nimeide.oss-cn-beijing.aliyuncs.com/" + fileName;
        return url;
    }
}
